<template>
	<view>
		<cu-custom bgColor="bg-gradual-blue" :isBack="true">
			<block slot="backText">返回</block>
			<block slot="content">文件预览</block>
		</cu-custom>
		<iframe :style="[{ height: 'calc(100vh - ' + CustomBar + 'px - 50px)' }]" style="width:100%;" :src="fileUrl" ref="iframe"></iframe>
	</view>
</template>

<script>
export default {
	data() {
		return {
			fileUrl:"",
			CustomBar: this.CustomBar,
			Excel:
				'https://hk2-excel.officeapps.live.com/x/_layouts/mobile/mXL.aspx?ui=zh-CN&rs=zh-CN&WOPISrc=http://hk2-view-wopi.wopi.live.net:808/oh/wopi/files/@/wFileId?wFileId=*****&access_token_ttl=0&access_token=1&wdMobileHost=2',
			Word:
				'https://hk2-word-view.officeapps.live.com/wv/mWord.aspx?ui=zh-CN&rs=zh-CN&WOPISrc=http://hk2-view-wopi.wopi.live.net:808/oh/wopi/files/@/wFileId?wFileId=*****&access_token_ttl=0&access_token=1&wdMobileHost=2',
			Pdf: '',
			PPT:
				'https://hk2-powerpoint.officeapps.live.com/p/mPPT.aspx?PowerPointView=ReadingView&ui=zh-CN&rs=zh-CN&WOPISrc=http://hk2-view-wopi.wopi.live.net:808/oh/wopi/files/@/wFileId?wFileId=*****&access_token_ttl=0&access_token=1&wdMobileHost=2'
		};
	},
	onLoad(e) {
		let url = e.url;
		console.log(url)
		let type = this.getType(url);
		console.log(type)
		// word
		if (type == '.doc' || type == '.docx') {
			this.fileUrl = this.Word.replace("*****", url);
		}
		// excel
		if (type == '.xls' || type == '.xlsx') {
			this.fileUrl = this.Excel.replace("*****", "");
		}
		// ppt
		if (type == '.ppt' || type == '.docx') {
			this.fileUrl = this.PPT.replace("*****", "");
		}
	},
	methods: {
		// 获取文件后缀
		getType(file) {
			var filename = file;
			var index1 = filename.lastIndexOf('.');
			var index2 = filename.length;
			var type = filename.substring(index1, index2);
			return type;
		}
	}
};
</script>

<style></style>
